package com.example.demo;

import javax.annotation.Resource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.service.BookService;

@SpringBootApplication
@Controller
@EnableCaching
public class SpringCacheDemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringCacheDemoApplication.class, args);
	}
	
	@Resource
	private RedisTemplate<String, Object> redisTemplate;
	
	@Resource
	private BookService bookService;
	@GetMapping("hello")
	@ResponseBody
	public Object hello() {
		ValueOperations<String, Object> opsForValue = redisTemplate.opsForValue();
		opsForValue.set("age", 18);
		Object object = opsForValue.get("age");
		
		return object;
	}
	
	@GetMapping("cache")
	@ResponseBody
	public Object testCache() {
		return bookService.getBookName();
	}
	@GetMapping("clear")
	@ResponseBody
	public Object testClearCache() {
		return bookService.clearBookname();
	}

}

